﻿using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

using Ordinaire.Data;

namespace Ordinaire.Taxonomy.Data
{
    /// <summary>
    /// An example of default table used to contain taxonomies.
    /// </summary>
    [Table]
    public class Taxonomies : HierarchyData<int, string>
    {
        #region Variables

        /// <summary>
        /// Row id.
        /// </summary>
        private int rowId;

        /// <summary>
        /// Storage for association 'FK_Taxonomies_Vocabs'.
        /// </summary>
        private EntityRef<Vocabs> vocabs = new EntityRef<Vocabs>();

        #endregion

        #region Property methods

        /// <summary>
        /// Get or set the row id.
        /// </summary>
        [Column(Name = "Id", DbType = "int IDENTITY NOT NULL", IsDbGenerated = true, UpdateCheck = UpdateCheck.Never)]
        public int RowId
        {
            get { return rowId; }
            set { rowId = value; }
        }

        /// <summary>
        /// Get or set the corresponding id of ClickPOS.Taxonomy.Data.Vocabs.
        /// </summary>
        [Column(Name = "VocabId", DbType = "int NOT NULL", IsPrimaryKey = true, UpdateCheck = UpdateCheck.Never)]
        public override int Id
        {
            get { return base.Id; }
            set { base.Id = value; }
        }

        /// <summary>
        /// Get or set the corresponding parent id of ClickPOS.Taxonomy.Data.Vocabs.
        /// </summary>
        [Column(Name = "ParentVocabId", DbType = "int NOT NULL", IsPrimaryKey = true, UpdateCheck = UpdateCheck.Never)]
        public override int ParentId
        {
            get { return base.ParentId; }
            set { base.ParentId = value; }
        }

        /// <summary>
        /// Get or set the username who created this entry.
        /// </summary>
        [Column(DbType = "nvarchar(10) NOT NULL", UpdateCheck = UpdateCheck.Never)]
        public override string CreatedBy
        {
            get { return base.CreatedBy; }
            set { base.CreatedBy = value; }
        }

        /// <summary>
        /// Get or set the date when the entry was first created.
        /// </summary>
        [Column(DbType = "datetime NOT NULL DEFAULT(GETDATE())", UpdateCheck = UpdateCheck.Never)]
        public override DateTime? CreateDate
        {
            get { return base.CreateDate; }
            set { base.CreateDate = value; }
        }

        /// <summary>
        /// Get or set the username who last updated this entry.
        /// </summary>
        [Column(DbType = "nvarchar(10) NULL", CanBeNull = true, UpdateCheck = UpdateCheck.Never)]
        public override string UpdatedBy
        {
            get { return base.UpdatedBy; }
            set { base.UpdatedBy = value.TrimOrEmpty(); }
        }

        /// <summary>
        /// Get or set the date when the entry was last updated.
        /// </summary>
        [Column(DbType = "datetime NULL", CanBeNull = true, UpdateCheck=UpdateCheck.Never)]
        public override DateTime? UpdateDate
        {
            get { return base.UpdateDate; }
            set { base.UpdateDate = value; }
        }

        #endregion

        #region Association

        /// <summary>
        /// Gets or sets the associated data from table 'People'.
        /// </summary>
        [Association(Name = "FK_Taxonomies_Vocabs", IsForeignKey = true, ThisKey = "Id", Storage = "vocabs")]
        public Vocabs Vocabs
        {
            get { return vocabs.Entity; }
            set { vocabs.Entity = value; }
        }

        #endregion

        #region Expression

        /// <summary>
        /// Returns a related expression to select the associated keyword/name of current data.
        /// </summary>
        /// <returns>the related expression</returns>
        public static Expression<Func<Taxonomies, string>> GetName()
        {
            return d => d.Vocabs.Name;
        }

        /// <summary>
        /// Returns a related expression where id is equal to the specified id.
        /// </summary>
        /// <param name="id">the value of id to compare</param>
        /// <returns>the related expression</returns>
        public static Expression<Func<Taxonomies, bool>> IdIs(int id)
        {
            return d => d.Id == id;
        }

        /// <summary>
        /// Returns a related expression where parent id is equal to the specified id.
        /// </summary>
        /// <param name="id">the value of parent id to compare</param>
        /// <returns>the related expression</returns>
        public static Expression<Func<Taxonomies, bool>> ParentIdIs(int id)
        {
            return d => d.ParentId == id;
        }

        #endregion
    }
}
